package io.datajek.springbasics.movierecommendersystem.lesson11;

import io.datajek.springbasics.movierecommendersystem.lesson2.Filter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;


@Component
public class RecommenderImplementation {

    //使用过滤器接口选择过滤器
   @Autowired
   @Qualifier("cf")
    private Filter filter;

   private Logger logger= LoggerFactory.getLogger(this.getClass());

    public void setFilter(Filter filter) {
        logger.info("In RecommenderImplementation setter method..dependency injection");
        this.filter = filter;
    }
  @PostConstruct
    public void postConstruct(){
        logger.info("In RecommenderImplementation postConstruct method");
    }

    @PreDestroy
    public void preDestroy(){
        System.out.println("In RecommenderImplementation preDestroy method");
    }
    //使用过滤器来获得推荐
    public String[] recommendMovies(String movie){

        //打印正在使用的接口实现的名称
        System.out.println("正在使用的过滤器名称：" + filter );


        String[] result= filter.getRecommendations("推荐电影");
        return  result;
    }
}